package com.ms.demo.cglibproxy;

import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;
import java.util.Arrays;

/**
 * @description: 实现MethodInterceptor
 * @author: ms
 * @create: 2022-10-26 17:01
 */
public class ImageInterceptor implements MethodInterceptor {

    private Image target;//目标对象

    public ImageInterceptor(Image image) {
        this.target = image;
    }

    /**
    * @Description: intercept
    * @Param: [o, method, objects, methodProxy]  o:代理对象  method : 被代理对象的方法  objects:方法入参    methodProxy:代理方法
    * @return: java.lang.Object
    * @Date: 2022/10/27 14:48
    */
    @Override
    public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
        System.out.println("目标方法执行前执行，[方法名为: "+ method.getName() +"] ; [参数为: " + objects.length+"]");
        Object result = methodProxy.invokeSuper(o, objects);
        return o;
    }
}